public class FindNumberIn2DArray {

    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix.length == 0) return false;
        int maxRow = matrix.length;
        int maxcol = matrix[0].length;
        int row = 0;
        int col = maxcol - 1;

        while (row < maxRow && col >= 0) {
            if (matrix[row][col] > target) {
                col--;
            } else if (matrix[row][col] < target) {
                row++;
            } else return true;
        }
        return false;
    }
}
